using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Method
    {
        public static void Test()
        {
            Console.WriteLine("Hello World!");

            string i1 = "请输入第一个数字";
            int a = Exception(i1);
            string i2 = "请输入第二个数字";
            int b = Exception(i2);
            int temp = a;
            Console.WriteLine("a -- > " + a + " ,b -- > " + b);

            a = b;
            b = temp;
            Console.WriteLine("a -- > " + a + " ,b -- > " + b);
        }

        public static void PI()
        {
            double pi = 3.14;
            string info = "请输入一个数字计算圆的面积";
            int a = Exception(info);
            Console.WriteLine(pi * a * a);
        }
        public static void FourBitNumber()
        {
            String info = "请输入一个四位数数字：";
            int a = Exception(info);
            int b = a / 1000;
            int c = a / 100 % 10;
            int d = a / 10 % 10;
            int f = a % 10;

            Console.WriteLine("a -- > " + b + " , b -- > " + c + " , c -- > " + d + " , d -- >" + f);
        }

        public static void Max()
        {
            int[] arr = new int[10];
            for (int i = 0; i < arr.Length; i++)
            {
                string info = "请给第" + （i + 1） + "个数字赋值";
                int a = Exception(info);
                arr[i] = a;
            }
            int max = arr[0];
            for (int i = 0; i < arr.Length; i++)
            {
                if (max < arr[i]) max = arr[i];
            }
            Console.WriteLine("max --> " + max);
        }

        public static int Exception(string info) {
            while (true)
            {
                try
                {
                    Console.WriteLine(info);
                    string a = Console.ReadLine();
                    int b = int.Parse(a);
                    return b;
                }
                catch (FormatException e)
                {
                    Console.WriteLine("输入错误，请重新输入");
                }
            }
        }
    }
}
